<extend name="Public:mainbase" />
<block name="content">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/dhtmlxtree.css"/>
<script language="javascript" src="__PUBLIC__/js/member.js?{:time()}"></script>  
<script language="javascript" src="__PUBLIC__/js/Validform_v5.3.2_min.js?{:time()}"></script> 
<style type="text/css">
	.Validform_checktip{line-height: 34px}
</style> 
<!--  内容列表   -->
<form name="form2" method="post">
<table width="98%" class="table table-bordered  table-hover table-condensed "  align="center">
<tr bgcolor="#E7E7E7" >
	<td height="28" colspan="12" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
	◆ 用户列表 &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target=".newuserbox"><i class="glyphicon glyphicon-plus"></i> 添加用户</button>
	</td>
</tr>
<tr align="center" bgcolor="#FBFCE2" height="25">
	<td width="6%">ID</td>
	<td width="4%">选择</td>
	<td width="9%">用户名</td>
	<td width="9%">真实姓名</td>
	<td width="9%">拼音</td>
	<td width="9%">手机</td>
	<td width="9%">频道</td>
	<td width="9%">职位</td>
	<td width="9%">创建时间</td>
	<td width="9%">最后登录时间</td>
	<td width="9%">状态</td>
	<td width="9%">操作</td>
</tr>
<foreach name="userList" item="val">
<tr align='center' bgcolor="#FFFFFF" height="26">
	<td nowrap>{$val.uid}</td>
	<td>
		<input name="uid" type="checkbox" value="{$val.uid}" class="np" />
	</td>
	<td>{$val.username}</td>
	<td>{$val.realname}</td>
	<td>{$val.realnamepy}</td>
	<td>{$val.mobile}</td>	
	<td>{$val.channelname}</td>	
	<td>{$val.jobsname}</td>	
	<td>{$val.createtime|myDate="Y-m-d H:i",###}</td>
	<td>{$val.lastlogintime|myDate="Y-m-d H:i",###}</td>
	<td><eq name="val.userstatus" value="1">开启<else />冻结</eq></td>
	<td>
		<a href="javascript:;" data-uid='{$val.uid}' class='edituser'>修改</a>
		|
		<a href="javascript:;" data-userAuth='{$val.userauth}' data-uid='{$val.uid}' class='setUserAuth'>设置权限</a>
		|
		<a href="javascript:;" data-uid='{$val.uid}' class='deluser'>删除</a>
	</td>
</tr>
</foreach>
<tr bgcolor="#ffffff">
<td height="36" colspan="12">
	&nbsp;
	<a href="javascript:selAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-ok'></i> 全选</a>
	<a href="javascript:noSelAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-remove'></i> 取消</a>
	<!-- <a href="javascript:checkArc(0)" class="btn btn-xs btn-info">&nbsp;审核&nbsp;</a> -->
	<a href="javascript:;" id="deluserall" class="btn btn-xs btn-info"><i class="glyphicon glyphicon-trash"></i> 删除</a>
</td>
</tr>
</form>
<tr align="right" bgcolor="#F9FCEF">
	<td height="36" colspan="12" align="center">
		<div class='page'>{$showPage}</div>
	</td>
</tr>
</table>

<!--  搜索表单  -->
<form name='form3' action='{:U('Admin/User/index')}' method='get'>
<input type='hidden' name='dopost' value='listArchives' />
<table width='98%'  class='table' align="center" style="margin-top:8px">
  <tr bgcolor='#EEF4EA'>
    <td background='__PUBLIC__/images/wbg.gif' align='center'>
      <table border='0' cellpadding='0' cellspacing='0' height="32">
        <td nowrap>手机号码：</td>
        <td width='130'>
          	<input type='text' name='mobile' value='' style='width:120px' />
        </td>
        <td nowrap>用户名：</td>
        <td width='130'>
          	<input type='text' name='username' value='' style='width:120px' />
        </td>
       <td>
          <input  type="image" src="__PUBLIC__/images/button_search.gif" width="60" height="22" border="0" class="np" />
       </td>
      </tr>
     </table>
   </td>
  </tr>
</table>
</form>


<!-- 添加用户弹窗 -->
<div class="modal fade newuserbox" tabindex="-1" Auth="dialog" aria-labelledby="add_user_jump" id='newuserbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">添加用户信息</h4>
	    </div>
		<form action="{:U('addUserAction')}" method="POST" class="form-horizontal" id="adduserform" style="padding:15px 0">
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">用户名</label>
			<div class="col-sm-5">
				<input name="username" type="text" placeholder="请输入用户名" datatype="*2-30" ajaxurl="{:U('ajaxcheckusername')}" sucmsg=" " errormsg="用户名为2-30个字符" nullmsg="用户名必须填写"  ignore='ignore' class="form-control" value="">
				<!-- <input name="username" type="text" placeholder="请输入用户名" class="form-control" value=""> -->
			</div>
			<div class="col-sm-5"></div>
		</div>

        <div class="form-group">
	        <label for="password" class="col-sm-2 control-label">密码</label>
	        <div class="col-sm-5">
	        	<input name="password" type="password" placeholder="请输入密码,不得少于6位" class="form-control" datatype="*6-30"  sucmsg=" " errormsg="密码为6-30个字符" nullmsg="密码必须填写" value="123456">
			</div>
			<div class="col-sm-5"></div>
        </div>

		<div class="form-group">
			<label for="realname" class="col-sm-2 control-label">真实姓名</label>
			<div class="col-sm-5">
				<input name="realname" type="text" placeholder="请输入用户真实姓名" datatype="zh2-30"  sucmsg=" " errormsg="请输入真实姓名" ignore='ignore' value="" class="form-control">
			</div>
			<div class="col-sm-5"></div>
		</div>


		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">用户组</label>
			<div class="col-sm-5">
				<select name="usergroup" class="form-control" datatype="*" nullmsg='请选择用户所属组' sucmsg=" ">
					<option value="">-- 请选择用户所属组 --</option>
					<volist name='userGroupList' id='userGroup'>
					<option value="{$userGroup.groupid}">{$userGroup.groupname}</option>
					</volist>
				</select>
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">所属频道</label>
			<div class="col-sm-5">
				<select name="userchannel" class="form-control" datatype="*" nullmsg='请选择用户所属频道' sucmsg=" ">
					<option value="">-- 请选择用户所属频道 --</option>
					<volist name='channellist' id="channel">
					<option value="{$channel.chid}">{$channel.name}</option>
					</volist>
				</select>
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">职位</label>
			<div class="col-sm-5">
				<select name="userjobs" class="form-control" datatype="*" nullmsg='请选择用户所属职位' sucmsg=" ">
				<option value="">-- 请选择用户职位 --</option>
				<volist name='joblist' id="job">
				<option value="{$job.jid}">{$job.name}</option>
				</volist>
			</select>
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="form-group">
			<label for="email" class="col-sm-2 control-label">邮箱</label>
			<div class="col-sm-5">
				<input name="email" type="text" placeholder="请输入用户邮箱地址" datatype='e' success=' ' errormsg='邮箱格式错误' ignore='ignore' value="" class="form-control" ajaxurl="{:U('ajaxEmailCheck')}">
			</div>

			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="mobile" class="col-sm-2 control-label">手机</label>
			<div class="col-sm-5">
				<input name="mobile" type="text" placeholder="请输入用户手机号码" datatype='m2' success=' ' nullmsg='手机为必填项' errormsg='手机格式错误' ajaxurl="{:U('ajaxMobileCheck')}"  value="" class="form-control">
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="status" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-5">
				<input id="add-status_1" name="status" type="radio" value="1" checked="checked">
				<label for="add-status_1">启用</label>&nbsp;&nbsp;
				<input id="add-status_0" name="status" type="radio" value="0">
				<label for="add-status_0">冻结</label>
			</div>
		</div>
		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="submit" class="btn btn-success">确定添加</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>


<!-- 修改用户弹窗 -->
<div class="modal fade edituserbox" tabindex="-1" Auth="dialog" aria-labelledby="edit_user_jump" id='edituserbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
	    </div>
		<form action="{:U('editUserAction')}" method="POST" class="form-horizontal" style="padding:15px 0">
		<input name='uid' type="hidden" value=''>
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">用户名</label>
			<div class="col-sm-5">
				<input name="username" type="text" placeholder="请输入用户名" datatype="*2-30" sucmsg=" " errormsg="用户名为2-30个字符" nullmsg="用户名必须填写" class="form-control" value="" ignore ajaxurl="{:U('ajaxcheckusername')}">
			</div>
			<div class="col-sm-5"></div>
		</div>

        <div class="form-group">
	        <label for="password" class="col-sm-2 control-label">密码</label>
	        <div class="col-sm-5">
	        	<input name="password" type="password" placeholder="如密码不修改，请留空" class="form-control" datatype="*6-30"  sucmsg=" " errormsg="密码为6-30个字符" ignore='ignore' value="123456">
			</div>
			<div class="col-sm-5"></div>
        </div>

		<div class="form-group">
			<label for="realname" class="col-sm-2 control-label">真实姓名</label>
			<div class="col-sm-5">
				<input name="realname" type="text" placeholder="请输入用户真实姓名" datatype="zh2-30"  sucmsg=" " errormsg="请输入真实姓名" ignore='ignore' value="" class="form-control">
			</div>
			<div class="col-sm-5"></div>
		</div>


		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">用户组</label>
			<div class="col-sm-5">
				<select name="usergroup" class="form-control" datatype="*" nullmsg='请选择用户所属组' sucmsg=" ">
					<option value="">-- 请选择用户所属组 --</option>
					<volist name='userGroupList' id='userGroup'>
					<option value="{$userGroup.groupid}">{$userGroup.groupname}</option>
					</volist>
				</select>
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">所属频道</label>
			<div class="col-sm-5">
				<select name="userchannel" class="form-control" datatype="*" nullmsg='请选择用户所属频道' sucmsg=" ">
					<option value="">-- 请选择用户所属频道 --</option>
					<volist name='channellist' id="channel">
					<option value="{$channel.chid}">{$channel.name}</option>
					</volist>
				</select>
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">职位</label>
			<div class="col-sm-5">
				<select name="userjobs" class="form-control" datatype="*" nullmsg='请选择用户所属职位' sucmsg=" ">
				<option value="">-- 请选择用户职位 --</option>
				<volist name='joblist' id="job">
				<option value="{$job.jid}">{$job.name}</option>
				</volist>
			</select>
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="form-group">
			<label for="email" class="col-sm-2 control-label">邮箱</label>
			<div class="col-sm-5">
				<input name="email" type="text" placeholder="请输入用户邮箱地址" datatype='e' success=' ' errormsg='邮箱格式错误' ignore='ignore' value="" class="form-control" ajaxurl="{:U('ajaxEmailCheck')}>
			</div>

			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="mobile" class="col-sm-2 control-label">手机</label>
			<div class="col-sm-5">
				<input name="mobile" type="text" placeholder="请输入用户手机号码" datatype='m2' success=' ' nullmsg='手机为必填项' errormsg='手机格式错误'   value="" class="form-control" ajaxurl="{:U('ajaxMobileCheck')}>
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="status" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-5">
				<input id="edit_status_1" name="edit_status" type="radio" value="1" checked="checked">
				<label for="edit_status_1">启用</label>&nbsp;&nbsp;
				<input id="edit_status_0" name="edit_status" type="radio" value="0">
				<label for="edit_status_0">冻结</label>
			</div>
		</div>
		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="submit" class="btn btn-success">确定修改</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>

<!-- 修改用户权限 -->
<div class="modal fade setuserAuthbox" tabindex="-1" Auth="dialog" aria-labelledby="set_userAuth_jump" id='setuserAuthbox'>
  <div class="modal-dialog modal-sm" style="width:320px">
  		
    <div class="modal-content"  style="height:420px">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="setuserAuthboxLabel">修改用户权限</h4>
	    </div>
		<div class="modal-body">
			<div id="treeboxbox_tree2"  style="width:98%;margin:0 auto; height:268px; border:1px solid #ccc;overflow:auto;"></div>
			<input type="hidden" id="id">
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-primary" id="saveAuth"><i class="glyphicon glyphicon-ok"></i> 确定</button>
        	<button type="button" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> 取消</button>
		</div>
    </div>
  </div>
</div>
<script src="__PUBLIC__/js/dhtmlxtree.js"></script>
<script type="text/javascript">
//myTree.load("{:U('AuthTree')}?Authlist=3,4,13,14", "json");
	$('.deluser').click(function(){
		if(confirm('是否确定删除此用户？')){
			var obj=this;
			$.get('{:U("ajaxdeluer")}?uid='+$(obj).data('uid'),function(data){
				if(data==1){
					$(obj).parents('tr').remove();
				}
			})
		}
	})

	$('#deluserall').click(function(){
		if(confirm('是否确定删除？')){
			var id=$('[name=uid]:checked').map(function(){
				return $(this).val();
			}).get().join()
			
			$.get('{:U("ajaxdeluerall")}?uid='+id,function(data){
				if(data==1){
					$('[name=uid]:checked').parents('tr').remove();
				}
			})
		}
	})

	$('#newuserbox').on('show.bs.modal', function (e) {
  		$('#newuserbox form').get(0).reset();
  		$('#newuserbox .Validform_checktip').empty().attr('class','Validform_checktip');
  		$('.Validform_error').removeClass('Validform_error');
	})
	$.ajaxSetup({cache:false})
	$('.edituser').click(function(){
		$('#edituserbox form').get(0).reset();
		$.getJSON("{:U('ajaxgetuserinfo')}?uid="+$(this).data('uid'),function(data){
  			if(data!=0){
  				$("#edituserbox [name=uid]").val(data.uid);
  				$("#edituserbox [name=username]").val(data.username);
  				$("#edituserbox [name=username]").attr('ajaxurl', '{:U("ajaxcheckusername")}?uid=' + data.uid);
  				$("#edituserbox [name=realname]").val(data.realname);
  				$("#edituserbox [name=email]").val(data.email);
  				$("#edituserbox [name=email]").attr('ajaxurl', '{:U("ajaxEmailCheck")}?uid=' + data.uid);
  				$("#edituserbox [name=mobile]").val(data.mobile);	
  				$("#edituserbox [name=mobile]").attr('ajaxurl', '{:U("ajaxMobileCheck")}?uid=' + data.uid);
  				$("#edituserbox [name=usergroup]").val(data.usergroup);			
  				$("#edit_status_"+data.status).get(0).checked=true;
  				if(data.userchannel!=0)
  				$("#edituserbox [name=userchannel]").val(data.userchannel);
  			 	if(data.userjobs!=0)
  				$("#edituserbox [name=userjobs]").val(data.userjobs);

  				/*$("#edituserbox [name=mobile]").attr('ajaxurl',geturl($("#edituserbox [name=mobile]").attr('ajaxurl'))+'?uid='+data.uid);
  				$("#edituserbox [name=username]").attr('ajaxurl',geturl($("#edituserbox [name=username]").attr('ajaxurl'))+'?uid='+data.uid);
  				$("#edituserbox [name=email]").attr('ajaxurl',geturl($("#edituserbox [name=mobile]").attr('ajaxurl'))+'?uid='+data.uid);*/
  			}
  		})
  		$('#edituserbox .Validform_checktip').empty().attr('class','Validform_checktip');
  		$('.Validform_error').removeClass('Validform_error');
		$('#edituserbox').modal('show');
	})

	$("form").Validform({
		tiptype:2,
		showAllError:true,
		datatype:{
			"zh2-30":/^[\u4E00-\u9FA5\uf900-\ufa2d]{2,30}$/,
			"m2": /^1[0-9]{2}[0-9]{8}$/
		},
	})

	function geturl($url){
		$a=$url.split('?');
		return $a[0];
	}

	var myTree = new dhtmlXTreeObject("treeboxbox_tree2","100%","100%",0);
	myTree.enableCheckBoxes(true,true);
	myTree.enableThreeStateCheckboxes(true);
	myTree.setDataMode("json");
	myTree.setImagePath("__PUBLIC__/images/dhxtree_skyblue/");

	$(".setUserAuth").click(function(){
		myTree.deleteChildItems(0);
		myTree.load("{:U('authTree')}?authlist="+$(this).data('userauth'),"json");
		$("#setuserAuthbox").modal('show');
		$("#id").val($(this).data('uid'));
	})

	$("#saveAuth").click(function(){
		if(confirm('是否确定修改此用户的权限？')){
			var idList = myTree.getAllChecked();
			$.ajax({cache:false});
			$.get("{:U('ajaxSetUserAuth')}",{idList:idList,uid:$("#id").val()},function(data){
				if(data==1){
					$("#id").val('');
					location.reload();
				}else{
					alert('修改失败！稍后重试！');
				}
			});
		}
	})
</script>




</block>